<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
class ajaxController extends Controller
{
    public function index(Request $request)
    {
	//判断是否登录
    //yes代表登录，no代表没登录
		if (session()->has('homeuser')){
			// echo json_encode($request->input('num'));
			$pro = DB::table('product')->where('id',$request->input('id'))->first();
	    	$user = DB::table('user')->where('id',session('homeuser')->id)->first();
	    	$id = DB::table('car')->insertGetId(
				['product_id' => "$pro->id", 'user_id' => "$user->id", 'num' =>$request->input('num'), 'pic' => "$pro->picture", 'price' => "$pro->lower_price", 'name' => "$pro->name" ]
			);
			echo json_encode('yes');
		}else{
			echo json_encode('no');
		}
		// echo json_encode(num);

    }

    public function shopcar(Request $request)
    {	
    	// dd($id);
    	// dd(session('homeuser')->id);
  //   	if(session()->has('homeuser')){
  //   		$pro = DB::table('product')->where('id',$id)->first();
	 //    	$user = DB::table('user')->where('id',session('homeuser')->id)->first();
	 //    	$id = DB::table('car')->insertGetId(
		// 		['product_id' => '$pro->id', 'user_id' => '$user->id', 'num' => ]
		// 	);

		// 	return view('car.successtocar');
		// }else{
		// 	return redirect('/home/gologin');
		// }
		// echo json_encode($request->input('num'));
		return view('car.successtocar');

    }
    
    
}
